package com.oschina.bottle.log4j2.lookup;

import com.oschina.bottle.log4j2.spring.SpringContext;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.lookup.AbstractLookup;
import org.apache.logging.log4j.core.lookup.StrLookup;

/**
 * spring环境变量替换插件
 *
 * @author <a href="mailto:zhongchao@gegejia.com">zhong</a>
 * @version 1.0 2016/11/21
 * @since 1.0
 */
@Plugin(name = "spring", category = StrLookup.CATEGORY)
public class SpringEnvrionmentLookup extends AbstractLookup
{
    @Override
    public String lookup(LogEvent event, String key)
    {
        if(SpringContext.getEnvironment() != null) {
            return SpringContext.getEnvironment().getProperty(key);
        }
        return null;
    }
}
